import 'package:flutter/material.dart';

class OverflowText extends StatelessWidget {
  final String text;
  final int maxLines;
  final TextStyle style;
  final TextOverflow overflow;
  final TextAlign textAlign;
  final bool softWrap;

  const OverflowText(
    this.text, {
    Key key,
    this.maxLines = 1,
    this.style,
    this.overflow = TextOverflow.ellipsis,
    this.textAlign,
    this.softWrap = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    String processedText = "";
    int feedLineCount = 0;
    for (int i = 0; i < text.length; i++) {
      if ("\n" == text[i]) {
        if (feedLineCount < maxLines - 1) {
          feedLineCount++;
          processedText += text[i];
        } else {
          processedText += "...";
          break;
        }
      } else {
        processedText += text[i];
      }
    }
    print(processedText);
    return Text(
      processedText,
      maxLines: maxLines,
      style: style,
      overflow: overflow,
      textAlign: textAlign,
      softWrap: softWrap,
    );
  }
}
